package com.songcha.sakura.ui.activity

import android.content.res.Configuration
import android.os.Bundle
import android.view.View
import com.songcha.library_base.base.BaseActivity
import com.songcha.library_common.util.StatusBarUtil
import com.songcha.library_common.util.ToastUtil
import com.songcha.sakura.databinding.*

class VideoActivity : BaseActivity() {
    private lateinit var binding:ActivityVideoBinding
    private var mUrl:String=""
    private var mTitle:String=""
    private var mIsLocal:Boolean=false


    override fun getRootView() : View? {
        binding = ActivityVideoBinding.inflate(layoutInflater)
        return binding.root
    }

    override fun isImmerseStatusBar(): Boolean {
        return true
    }

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)

        val params=intent.extras
        params?.let {
            mUrl=it.getString("url")?:""
            mTitle=it.getString("title")?:""
            mIsLocal=it.getBoolean("isLocal")?:false
            initVideo()
        }

    }

    override fun onResume() {
        super.onResume()
        StatusBarUtil.fullScreen(this)
        StatusBarUtil.setStatusBarStyle(this,true)
    }

    override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)
    }

    fun initVideo(){
        if(mUrl.isNullOrBlank()){
            ToastUtil.show("无效的视频地址")
            return
        }

        binding.cmvp.apply {
            setTitle(mTitle)
            setUrl(mUrl)
            getController().setTitle(mTitle)
        }

    }

    override fun onPause() {
        super.onPause()
        binding.cmvp.getMediaPlayer().pause()
        binding.cmvp.getController().apply {
            onPause()
            savePlayHistoryProgress()
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        binding.cmvp.getMediaPlayer().stop()
        binding.cmvp.getMediaPlayer().reset()
    }


    override fun isBaseOnWidth(): Boolean {
        return false
    }

    override fun getSizeInDp(): Float {
        return 360f
    }


}